#include "StdAfx.h"
#include "UIEventSet.h"
#include <CEGUIEventSet.h>

void UIEventSetIterator_Next(CEGUI::EventSet::Iterator* self)
{
	self++;
}

void UIEventSetIterator_Previous(CEGUI::EventSet::Iterator* self)
{
	self--;
}

void SubscribeScriptedEventToDefaultGroup(CEGUI::EventSet*self,const CEGUI::String& name, const CEGUI::String& subscriber_name)
{
	self->subscribeScriptedEvent(name,subscriber_name);
}

void SubscribeScriptedEventToGroup(CEGUI::EventSet*self,const CEGUI::String& name,CEGUI::Event::Group group, const CEGUI::String& subscriber_name)
{
	self->subscribeScriptedEvent(name,group,subscriber_name);
}

void ScriptBackend::Module_UIEventSet( lua_State* l )
{
	using namespace luabind;
	using namespace CEGUI;

	module(l)
		[
			class_<EventSet::Iterator>("UIEventSetIterator")
			.property("CurrentKey",&EventSet::Iterator::getCurrentKey)
			.property("CurrentValue",&EventSet::Iterator::getCurrentValue)
			.property("IsAtEnd",&EventSet::Iterator::isAtEnd)
			.property("IsAtStart",&EventSet::Iterator::isAtStart)
			.def("ToEnd",&EventSet::Iterator::toEnd)
			.def("ToStart",&EventSet::Iterator::toStart)
			.def("Next",&UIEventSetIterator_Next)
			.def("Previous",&UIEventSetIterator_Previous)
			.def(const_self == other<const EventSet::Iterator&>())
			,
			class_<EventSet>("UIEventSet")
			.def("IsEventPresent",&EventSet::isEventPresent)
			.def("SubscribeEvent",&SubscribeScriptedEventToDefaultGroup)
			.def("SubscribeEvent",&SubscribeScriptedEventToGroup)
			.def("GetIterator",&EventSet::getIterator)
			.property("IsMuted",&EventSet::isMuted,&EventSet::setMutedState)
			,
			class_<EventArgs>("UIEventArgs")
			.def_readwrite("Handled",&EventArgs::handled)
			,
			class_<DisplayEventArgs,EventArgs>("UIDisplayEventArgs")
			.def_readonly("Size",&DisplayEventArgs::size)
			,
			class_<WindowEventArgs,EventArgs>("UIWidgetEventArgs")
			.def_readonly("Widget",&WindowEventArgs::window)
			,
			class_<ResourceEventArgs,EventArgs>("UIResourceEventArgs")
			.def_readonly("ResourceName",&ResourceEventArgs::resourceName)
			.def_readonly("ResourceType",&ResourceEventArgs::resourceType)				
		];
}